/*
 * usb_interface.h
 *
 *  Created on: 22.02.2009
 *      Author: fregat
 */

#ifndef USB_INTERFACE_H_
#define USB_INTERFACE_H_

# include <map>

namespace fregat {
namespace microchip {
namespace usb {

typedef std::string class_name_t;
typedef std::string method_name_t;

class jLogger;
class jException;

class exceptionInterface {
public :
	typedef enum {
		DEVICE_NOT_FOUND,
		CHANNEL_NOT_FOUND,
		INVALID_METHOD_ID,
		INVALID_LOG_LEVEL,
		INVALID_STATE,
		INVALID_CONFIG,
		DEVICE_NOT_CLAIMED,
		DEVICE_NOT_OPENED} exceptionID_t;
protected :
	virtual void doThrowException (jException *, exceptionInterface::exceptionID_t, std::string ) = 0;
public :
	void throw_exception (jException *pexc,exceptionInterface::exceptionID_t eid, std::string s)
	{
		doThrowException(pexc,eid,s);
	}

};

class logInterface {
public :
	typedef enum {INFO,DEBUG,FAULT} logLevel_t;
protected :
	virtual void doWriteLog (jLogger *, logLevel_t, std::string) = 0;
public :
	void write_log (jLogger *jl, logLevel_t ll, std::string s)
	{
		doWriteLog (jl, ll, s);
	}
};

class jException {
	std::map <exceptionInterface::exceptionID_t, class_name_t> excMap;
public :
	jException ()
	{
	}

	void addException (exceptionInterface::exceptionID_t eid, class_name_t cn)
	{
		excMap[eid] = cn;
	}

	class_name_t getExceptionClassName (exceptionInterface::exceptionID_t eid)
	{
		return excMap[eid];
	}
};

class jLogger {
public :
	typedef method_name_t	info_method_name_t;
	typedef method_name_t	debug_method_name_t;
	typedef method_name_t	error_method_name_t;
private :
	class_name_t		cname;
	info_method_name_t	infoname;
	debug_method_name_t	debugname;
	error_method_name_t	errorname;
public :
	jLogger (class_name_t cn, info_method_name_t in, debug_method_name_t dn, error_method_name_t en) :
		cname(cn), infoname(in), debugname(dn), errorname(en)
	{
	}
	void info (logInterface *li, std::string si)
	{
		li->write_log (this, logInterface::INFO,si);
	}
	void debug (logInterface *li, std::string sd)
	{
		li->write_log (this, logInterface::DEBUG, sd);
	}
	void error (logInterface *li, std::string se)
	{
		li->write_log (this, logInterface::FAULT, se);
	}

	inline class_name_t getClassName ()
	{
		return cname;
	}
	inline info_method_name_t getInfoMethodName ()
	{
		return infoname;
	}
	inline debug_method_name_t getDebugMethodName ()
	{
		return debugname;
	}
	inline error_method_name_t getErrorMethodName()
	{
		return errorname;
	}
};

}
}
}



#endif /* USB_INTERFACE_H_ */
